﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YJKFamilyLibDataManager;

namespace YJKFamilyLibManager.FamilyLibModule
{
	public partial class DlgSearchByTime : System.Windows.Forms.Form
	{
		public DateTime StartTime { get; set; }

		public DateTime EndTime { get; set; }

		public FamilyLibDatabase Database { get; set; }

		public DlgSearchByTime(List<FamilyLibDatabase> dbs)
		{
			this.mDbs = dbs;
			this.InitializeComponent();
			foreach (FamilyLibDatabase item in this.mDbs)
			{
				this.cbxSubject.Items.Add(item);
			}
			if (this.cbxSubject.Items.Count > 0)
			{
				this.cbxSubject.SelectedIndex = 0;
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		public static DlgSearchByTime GetInstance(Form main, List<FamilyLibDatabase> dbs)
		{
			if (DlgSearchByTime.dac == null || DlgSearchByTime.dac.IsDisposed)
			{
				DlgSearchByTime.dac = new DlgSearchByTime(dbs);
				DlgSearchByTime.dac.MdiParent = main.ActiveMdiChild;
			}
			else
			{
				DlgSearchByTime.dac.mDbs = dbs;
				DlgSearchByTime.dac.cbxSubject.Items.Clear();
				foreach (FamilyLibDatabase item in DlgSearchByTime.dac.mDbs)
				{
					DlgSearchByTime.dac.cbxSubject.Items.Add(item);
				}
				if (DlgSearchByTime.dac.cbxSubject.Items.Count > 0)
				{
					DlgSearchByTime.dac.cbxSubject.SelectedIndex = 0;
				}
			}
			return DlgSearchByTime.dac;
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.StartTime = this.dateTimePicker1.Value;
			this.EndTime = this.dateTimePicker2.Value;
			this.Database = (FamilyLibDatabase)this.cbxSubject.SelectedItem;
		}

		private void DlgSearchByTime_Load(object sender, EventArgs e)
		{
		}

		private void DlgSearchByTime_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private List<FamilyLibDatabase> mDbs = new List<FamilyLibDatabase>();

		private static DlgSearchByTime dac;
	}
}
